/**  
 * All rights Reserved, Designed By www.woniuxy.com
 * @Title:  Account.java   
 * @Package com.woniu.domain   
 * @Description:    Description  
 * @author: 蜗牛学院  
 * @date:   2019年7月24日 下午9:09:05
 * @user:   Administrator  
 * @version V1.0 
 * @Copyright: 2019 www.woniuxy.com Inc. All rights reserved. 
 * 注意：本内容仅限于成都蜗牛创想科技有限公司，禁止外泄以及用于其他的商业目
 */ 
package com.woniu.service.impl;

import java.sql.SQLException;
import java.util.List;

import com.woniu.dao.StuDao;
import com.woniu.dao.impl.StuDaoImpl;
import com.woniu.domain.Stu;
import com.woniu.service.StuService;

/**
 * @author Administrator
 *
 */
public class StuServiceImpl implements StuService {
	StuDao sd = new StuDaoImpl();
	@Override
	public List<Stu> Liststus() throws SQLException{
		
		return sd.ListStus();
	}
	@Override
	public boolean saveStu(Stu stu) throws SQLException {
		return sd.saveStu(stu) > 0;
	}
	@Override
	public void delStu(Integer sId) throws SQLException {
		sd.delStu(sId);
		
	}
	@Override
	public Stu findStu(Integer sId) throws SQLException {
		return sd.findStu(sId);
	}
	@Override
	public boolean updateStu(Stu stu) throws SQLException {
		return sd.updateStu(stu) > 0;
	}
	@Override
	public List<Stu> findStu(String sName, String sGender) throws SQLException {
		String sql = "select sid,sname,sgender,sage,shobby from stum where 1 = 1";
		//判断是否有值
		if(sName != null && sName.trim().length() != 0) {
			sql += " and sname like '%"+sName+"%'";
		}
		if(sGender !=null && sGender.trim().length() != 0) {
			sql += " and sgender = '"+sGender+"'";
		}
		return sd.fingStu(sql);
	}
	@Override
	public PageBean<Stu> queryStuByPage(int currentPage) throws SQLException {
		PageBean<Stu> pb = new PageBean<Stu>();
		/**
		 * 当前页号
		 */
		pb.setCurrentPage(currentPage);
		/**
		 * 设置每页
		 */
		pb.setPageSize(5);
		/**
		 * 实际数据
		 */
		List<Stu> list = sd.queryStuByPage(currentPage,pb.getPageSize());
		pb.setList(list);
		/**
		 * 总记录数
		 */
		int count = sd.countStus();
		pb.setTotalSize(count);
		/**
		 * 总页数
		 */
		pb.setTotalPage(count % pb.getPageSize() == 0 ? count / pb.getPageSize():(count/pb.getPageSize()+1));
		return pb;
	}

}
